<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>班级-学生</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style>
        body {
            background: rgba(90, 194, 255, 1);
        }

        .search {
            height: 30px;
            margin: 15px;
            background: rgba(255, 255, 255, 0.26);
            border-radius: 20px;
        }

        .search-icon {
            width: 17px;
            height: 16px;
            margin-right: 6px;
        }

        .search-text {
            font-size: 14px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
        }

        .class-item {
            margin: 15px;
            padding: 15px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }

        .class-arrow {
            width: 15px;
            height: 16px;
            min-width: 15px;
            ;
        }

        .class-name {
            font-size: 16px;
            font-weight: 500;
            color: rgba(25, 25, 25, 1);
            margin-bottom: 9px;
        }

        .teacher-avatar {
            width: 19px;
            height: 19px;
            border-radius: 50%;
            margin-right: 7px;
        }

        .teacher-name {
            font-size: 13px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
        }

        .btn {
            position: fixed;
            bottom: 15px;
            left: 50%;
            width: 210px;
            height: 46px;
            transform: translateX(-50%);
            background-image: url("../../image/course/btn_422x92.png");
            background-size: 100% 100%;
            background-repeat: no-repeat;
            line-height: 42px;
            box-shadow: 0px 4px 6px 0px rgba(11, 126, 193, 0.53);
            border-radius: 24px;
        }

        .btn-text {
            font-size: 18px;
            font-weight: 600;
            color: rgba(124, 69, 0, 1);
            text-align: center;
        }

        .btn-occupy {
            height: 46px;
            margin: 15px 0;
        }

        .class-number {
            vertical-align: text-bottom;
            font-size: 12px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="search" v-if="userType == 1" data-flex="main:center cross:center" @click="searchFn()">
            <div class="search-icon">
                <img src="../../image/ui/search.png" alt="">
            </div>
            <div class="search-text">搜索</div>
        </div>
        <div class="class-item" v-for="item in classes.retData" data-flex="cross:center" @click="classFn(item)">
            <div data-flex-box="1">
                <div class="class-name">{{ item.classesName }} <span class="class-number">（班级编号: {{ item.classesNumber }}）</span></div>
                <div data-flex="cross:center">
                    <img class="teacher-avatar" :src="item.icon || '../../image/ui/tea_def.png'" alt="">
                    <div class="teacher-name">{{ item.nickName }}</div>
                </div>
            </div>
            <div class="class-arrow">
                <img src="../../image/ui/arrow_right_2.png" alt="">
            </div>
        </div>
        <div class="data-null" v-show="dataNull">
            <p>{{ userType == '1' ? '您还未加入过班级' : '您还未创建过班级' }}</p>
        </div>
        <!-- 按钮占位 -->
        <div class="btn-occupy" v-if="userType == 2"></div>
        <div class="btn" v-if="userType == 2" data-flex="main:center" @click="createClass">
            <div class="btn-text">创建班级</div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        api.addEventListener({
            name: 'deleteStudent'
        }, function() {
            getPageData();
        });
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                classes: {
                    api: 'clsClass/findClassesList',
                    param: {},
                    retData: []
                },
                userType: USER.Get('memberType', true),
                dataNull: false
            }
        });
        getPageData();
        api.addEventListener({
            name: 'updateUserInfo'
        }, function () {
            getPageData();
            vm.userType = USER.Get('memberType', true);
        })
    }

    function getPageData() {
        var url = vm.classes.api;
        var params = vm.classes.param;
        $S.POST(url, params, function(ret) {
            if(ret.status == 200) {
                vm.classes.retData = ret.data.listData;
                vm.$nextTick(function() {
                    if(!vm.classes.retData.length) {
                        vm.dataNull = true;
                    } else {
                        vm.dataNull = false;
                    }
                })
                if (vm.userType == 1 && vm.classes.retData.length > 0) {
                    USER.Set({ 'classId': vm.classes.retData[0].id });
                };
            };
        });
    }

    function searchFn() {
        fnOpenWin({
            name: 'class_search_win',
            url: './class_search_win.html',
            pageParam: {
                type: 1
            }
        })
    }

    function classFn(item) {
        fnOpenPublicWin(
            item.classesName + '(' + (item.studentCount + 1) + '人)',
            'class/group',
            {
                isBtn: true,
                btnName: '班级详情',
                headerFn: 'headerFn',
                id: item.id
            }
        )
    }

    function createClass() {
        var schoolId = USER.Get('schoolId', true);
        if (schoolId !== '') {
            fnOpenFrame({
                name: 'create_class_frm',
                url: './create_class.html',
                pageParam: {
                    winName: api.winName,
                    frmName: api.frameName
                }
            })
        } else {
            fnToast('请先选择您所在的学校');
        }
    }
</script>

</html>